﻿using System;

class ModifyBitAtSpecificPosition
{
    static void Main()
    {
        int number;
        int bitValue;
        int bitPosition;

        Console.WriteLine("Type a number:");
        bool isNumberValid = int.TryParse(Console.ReadLine(), out number);
        Console.WriteLine("Type bit value:");
        bool isBitValueValid = int.TryParse(Console.ReadLine(), out bitValue);
        Console.WriteLine("Type position p:");
        bool isBitPositionValid = int.TryParse(Console.ReadLine(), out bitPosition);

        if (isNumberValid && isBitValueValid && isBitPositionValid)
        {
            int bitAtPosition = (number >> bitPosition) % 2;

            if (bitAtPosition == 1 && bitValue == 0)
            {
                int mask = ~(1 << bitPosition);
                number = number & mask;
            }

            if (bitAtPosition == 0 && bitValue == 1)
            {
                int mask = 1 << bitPosition;
                number = number | mask;
            }

            Console.WriteLine("Your number with changed bit value is:{0}",number);
        }
        else
        {
            Console.WriteLine("Your input isn`t OK!!!");
        }
    }
}